<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>案例5</title>
    <style>
        div {
            width: 200px;
            height: 200px;
            margin: 0 auto;
            background-color: white;
            text-align: center;
            line-height: 200px;
            color: black;
        }
        
        .bcd {
            width: 200px;
            height: 200px;
            margin: 0 auto;
            background-color: tomato;
            text-align: center;
            line-height: 200px;
            color: white;
        }
        
        .active {
            color: tomato;
            background-color: #fff;
            border: 1px solid tomato;
        }
    </style>
</head>

<body>
    <div id="asd" class="bcd">
        点我就就闪
    </div>
</body>

</html>
<script>
    var asd = document.querySelector("#asd")
    var timer
    var timer2
    let isStart = false
    asd.onclick = function() {
        if (isStart) {
            clearInterval(timer)
            clearTimeout(timer2)
            timer = undefined
            timer2 = undefined
            asd.className = "bcd"
            return
        }
        isStart = !isStart
        timer = setInterval(() => {
            asd.className += " active"
            timer2 = setTimeout(() => {
                asd.className = "bcd"
            }, 100);
        }, 200);
    }
</script>